package com.ssca.redis;

import org.json.JSONObject;


public class PopResultFromRedis {
	public IntentData popIntentData(){
		String JsonString = JedisUtil.rpop("intent");
//		String JsonString = JedisUtil.lindex("intent", index);
		JSONObject JsonObject = new JSONObject(JsonString);

		IntentData intentData = new IntentData();
		intentData.setSourceClass(convert(JsonObject.getString("sourceClass")));
		intentData.setSourcePkg(convert(JsonObject.getString("sourcePkg")));
		intentData.setDesClass(convert(JsonObject.getString("desClass")));
		intentData.setDesPkg(convert(JsonObject.getString("desPkg")));
		intentData.setUri(JsonObject.getString("uri"));
		intentData.setScheme(JsonObject.getString("scheme"));
		intentData.setHost(JsonObject.getString("host"));

		return intentData;
	}

	private static String convert(String s) {
		if(s==null||s.length()==0)
			return "";
		s=s.trim();
		String re;
		if(s.startsWith("L")&&s.endsWith(";")){
			re = s.substring(1, s.length() - 1);
			re = re.replaceAll("/", ".");
		}
		else
			re = s;
		
		
		
		return re;
	}

//	public static void main(String[] args) {
//		PopResultFromRedis fromRedis = new PopResultFromRedis();
//		IntentData data  = fromRedis.popIntentData(1);
//		System.out.println(data);
//	}
}
